-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add check to make sure the target paths are within the allowed mount directory #18
Conversation
within the allowed mount directory Github issue #2
@@ -171,6 +173,22 @@ QString SSNFSWorker::getPerms(QString path, qint32 uid) { | |||
} | |||
} | |||
|
|||
QByteArray SSNFSWorker::isValidPath(QByteArray path){ | |||
QString newPath = QTextCodec::codecForMib(1015)->toUnicode(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QTextCodec::codecForMib(1015)->toUnicode
is not required. Qt has a builtin operator=
to automatically convert QByteArray to QString http://doc.qt.io/qt-5/qstring.html#operator-eq-5
QStack<QString> normalizer; | ||
// Assuming the path starts and ends with / | ||
for (int i = 1; i < directories.size()-1; ++i){ | ||
if (QString::compare(directories.at(i),"..")){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QString::compare
is not required Qt has a built in operator==
to compare: http://doc.qt.io/qt-5/qstring.html#operator-eq-eq-1.
@@ -171,6 +173,22 @@ QString SSNFSWorker::getPerms(QString path, qint32 uid) { | |||
} | |||
} | |||
|
|||
QByteArray SSNFSWorker::isValidPath(QByteArray path){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why return a QByteArray? This function just performs a boolean (true/false only) check.
|
||
int res; | ||
|
||
struct stat stbuf; | ||
|
||
if (targetPath.isNull()){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the function is changed to return a boolean, it can just be called from the if
.
QString newPath = QTextCodec::codecForMib(1015)->toUnicode(path); | ||
QStringList directories = newPath.split("/"); | ||
QStack<QString> normalizer; | ||
// Assuming the path starts and ends with / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't assume anything. In fact, a path that does not start with a /
should be specifically reported as invalid.
Also, file paths definitely don't end with a /
.
If I removed the qCritical() and qInfo() message, the arguments are not being parsed correctly. So I retained them. Let me know if any changes need to be done.
Github issue #2